﻿@model CurrencyModel


@{
    var availableDomainEndings = Model.AvailableDomainEndings.Select(x => x.Value).ToArray();
    for (int i = 0; i < availableDomainEndings.Length; i++)
    {
        availableDomainEndings[i] = availableDomainEndings[i].EncodeJsString();
    }
    ViewBag.SerializedDomainEndings = String.Join(",", availableDomainEndings);
}
@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)
@Html.CafSite().TabStrip().Name("currency-edit").Items(x =>
{
    x.Add().Text(T("Admin.Common.Info").Text).Content(TabInfo()).Selected(true);
    x.Add().Text(T("Admin.Common.Sites").Text).Content(TabSites());

    //generate an event
    EngineContext.Current.Resolve<IEventPublisher>().Publish(new TabStripCreated(x, "currency-edit", this.Html, this.Model));
})
@helper TabInfo()
{
    <script type="text/javascript">
        $(document).ready(function () {

            var domainEndings = $("#@Html.FieldIdFor(x => x.DomainEndings)");
            domainEndings.select2({ tags: [@(Html.Raw(ViewBag.SerializedDomainEndings))] });

        });
    </script>
var cultures = System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures).ToList();
    @(Html.LocalizedEditor<CurrencyModel, CurrencyLocalizedModel>("currency-info-localized",
    @<div class="form-body">
        <div class="form-group">
            <label class="control-label col-md-2">
                @Html.LangLabelFor(model => model.Locales[item].Name)
            </label>
            <div class="col-md-6">
                @Html.TextBoxFor(model => Model.Locales[item].Name, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Locales[item].Name)

            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2">

            </label>
            <div class="col-md-6">
                @Html.HiddenFor(model => model.Locales[item].LanguageId)
            </div>
        </div>
    </div>
     ,
    @<div class="form-body">
        <div class="form-group">
            <label class="control-label col-md-2">
                @Html.LangLabelFor(model => model.Name)
            </label>
            <div class="col-md-6">
                @Html.TextBoxFor(model => model.Name, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Name)
            </div>
        </div>
    </div>))

    <div class="form-body">
        <div class="form-group">
            <label class="control-label col-md-2">
                @Html.LangLabelFor(model => model.CurrencyCode)
            </label>
            <div class="col-md-6">
                @Html.EditorFor(model => model.CurrencyCode, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.CurrencyCode)

            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2">
                @Html.LangLabelFor(model => model.Rate)
            </label>
            <div class="col-md-6">
                @Html.EditorFor(model => model.Rate, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Rate)

            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2">
                @Html.LangLabelFor(model => model.DisplayLocale)
            </label>
            <div class="col-md-6">
                @Html.DropDownListFor(x => x.DisplayLocale, cultures.Select(x =>
                new SelectListItem { Value = x.IetfLanguageTag, Text = string.Format("{0} [{1}]", x.DisplayName, x.IetfLanguageTag) }), new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.DisplayLocale)

            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2">
                @Html.LangLabelFor(model => model.CustomFormatting)
            </label>
            <div class="col-md-6">
                @Html.EditorFor(model => model.CustomFormatting, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.CustomFormatting)

            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2">
                @Html.LangLabelFor(model => model.DomainEndings)
            </label>
            <div class="col-md-6">
                @Html.EditorFor(model => model.DomainEndings, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.DomainEndings)

            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2">
                @Html.LangLabelFor(model => model.Published)
            </label>
            <div class="col-md-6">
                @Html.EditorFor(model => model.Published, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Published)

            </div>
        </div>
        <div class="form-group">
            <label class="control-label col-md-2">
                @Html.LangLabelFor(model => model.DisplayOrder)
            </label>
            <div class="col-md-6">
                @Html.EditorFor(model => model.DisplayOrder, new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.DisplayOrder)

            </div>
        </div>

        @if (Model.Id > 0)
    {
            <div class="form-group">
                <label class="control-label col-md-2">
                    @Html.LangLabelFor(model => model.CreatedOn)
                </label>
                <div class="col-md-6">
                    @Html.DisplayFor(model => model.CreatedOn)
                </div>
            </div>

        }
        <div class="form-group">
            <label class="control-label col-md-2">
                @Html.LangLabelFor(model => model.PrimarySiteCurrencySites)
            </label>
            <div class="col-md-6">
                @if (Model.PrimarySiteCurrencySites != null && Model.PrimarySiteCurrencySites.Count > 0)
                {
                    foreach (var store in Model.PrimarySiteCurrencySites)
                    {
                        <a href="@store.Value">@store.Text.NaIfEmpty()</a><br />
                    }
                }
                else
                {
                    <span class="muted">@T("Common.Unspecified")</span>
                }
            </div>
        </div>
    </div>
}
@helper TabSites()
{
    <script type="text/javascript">
        $(document).ready(function () {
            $('input[id="@Html.FieldIdFor(model => model.LimitedToSites)"]').on('switchChange.bootstrapSwitch', function (event, state) {
                toggleSiteMapping(state);
            });
            toggleSiteMapping(@Model.LimitedToSites.ToString().ToLower());
        });
        function toggleSiteMapping(state) {
            if (state) {
                $('#pnl-available-sites').show();
            }
            else {
                $('#pnl-available-sites').hide();
            }
        }

    </script>

    <div class="form-group">
        <label class="control-label col-md-2">
            @Html.LangLabelFor(model => model.LimitedToSites)
        </label>
        <div class="col-md-6">
            @Html.EditorFor(x => x.LimitedToSites)
            @Html.ValidationMessageFor(model => model.LimitedToSites)

        </div>
    </div>
    <div id="pnl-available-sites" class="form-group">
        <label class="control-label col-md-2">
            @Html.LangLabelFor(model => model.AvailableSites)
        </label>
        <div class="col-md-6">
            @if (Model.AvailableSites != null && Model.AvailableSites.Count > 0)
            {
                foreach (var store in Model.AvailableSites)
                {
                    <label class="checkbox">
                        <input type="checkbox" name="SelectedSiteIds" value="@store.Id" checked="@(Model.SelectedSiteIds != null && Model.SelectedSiteIds.Contains(store.Id))" />
                        <span>@store.Name</span>
                    </label>
                }
            }
            else
            {
                <div>@T("Admin.Configuration.Sites.NoSitesDefined")</div>
            }
        </div>
    </div>


}
